package com.jack.uikit.utils

import android.util.Log

/**
 * 日志帮助类
 *
 * @author Jack 2021-05-01 22:12
 */
class Logger {
    //是否开启日志
    private var mOpenLog = false
    private var mTag = ""

    companion object {
        private val instance: Logger by lazy {
            Logger()
        }

        fun get() = instance
    }

    class Builder {
        private val logger = get()

        var isOpen: Boolean
        get() = logger.mOpenLog
        set(value) {
            logger.mOpenLog = value
        }

        var tag: String
        get() = logger.mTag
        set(value) {
            logger.mTag = value
        }

    }

    fun e(tag: String = mTag, msg: String) {
        if (mOpenLog) {
            Log.e(tag, msg)
        }
    }

    fun i(tag: String = mTag, msg: String) {
        if (mOpenLog) {
            Log.i(tag, msg)
        }
    }

    fun d(tag: String = mTag, msg: String) {
        if (mOpenLog) {
            Log.d(tag, msg)
        }
    }
}

fun initLogger(builder: Logger.Builder.() -> Unit) {
    Logger.Builder().also(builder)
}